package com.itheima.plusstudentsystem;

import java.util.ArrayList;
import java.util.Random;

public class Test {
    public static void main(String[] args) {
        String str = getCode();
        System.out.println(str);

    }

    private static String getCode() {
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            list.add((char) ('a' + i));
            list.add((char) ('A' + i));
        }
        StringBuilder sb = new StringBuilder();
        Random r = new Random();
        for (int i = 0; i < 4; i++) {
            int index = r.nextInt(list.size());
            Character c = list.get(index);
            sb.append(c);
        }
        int i = r.nextInt(10);
        sb.append(i);
        char[] chars = sb.toString().toCharArray();
        int index = r.nextInt(chars.length);
        char temp = chars[index];
        chars[index]=chars[chars.length-1];
        chars[chars.length-1]=temp;
        return new String(chars);
    }
}
